//
//  YSSalaryDetailController.m
//  YaSha-iOS
//
//  Created by YaSha_Tom on 2017/12/13.
//  Copyright © 2017年 亚厦装饰股份有限公司. All rights reserved.
//

#import "YSSalaryDetailController.h"
#import "YSSalaryCell.h"
#import "YSSalaryHeaderView.h"
#import "YSSalaryRemarkCell.h"

@interface YSSalaryDetailController ()

@property (nonatomic,strong)YSSalaryHeaderView *headerView;
@property (nonatomic,strong)NSMutableArray *infoArr;
@property (nonatomic,strong)NSMutableArray *payArr;
@property (nonatomic,strong)NSMutableArray *welfareArr;
@property (nonatomic,strong)NSMutableArray *takeoutArr;
@property (nonatomic,strong)NSMutableArray *remarkArr;
@property (nonatomic,strong)NSArray *titleArray;
//@property (nonatomic,strong)NSMutableArray *dataSourceArray;

@end

@implementation YSSalaryDetailController

#pragma mark - 懒加载
- (NSArray *)titleArray{
    if (!_titleArray) {
        _titleArray = @[@"基本信息",@"应发工资",@"应发福利",@"代扣款项",@"备注"];
    }
    return _titleArray;
}
//- (NSMutableArray *)dataSourceArray{
//    if (!_dataSourceArray) {
//        _dataSourceArray = [NSMutableArray array];
//    }
//    return _dataSourceArray;
//}
- (YSSalaryHeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[YSSalaryHeaderView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 115)];
        
    }
    return _headerView;
}

- (void)setNavigationItemsIsInEditMode:(BOOL)isInEditMode animated:(BOOL)animated {
    [super setNavigationItemsIsInEditMode:isInEditMode animated:animated];
     self.title = @"我的薪资条";
}

- (void)initTableView {
    [super initTableView];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    self.tableView.backgroundColor = kUIColor(229, 229, 229, 1);
    self.tableView.contentInset = UIEdgeInsetsMake(10, 0, 0, 0);
    self.tableView.tableHeaderView = self.headerView;
    self.headerView.model = self.salaryModel;
    [self.tableView registerClass:[YSSalaryRemarkCell class] forCellReuseIdentifier:@"YSSalaryRemarkCell"];
    [self doNetworking];
    
}
- (void)doNetworking{
    self.infoArr = [NSMutableArray array];
    self.payArr = [NSMutableArray array];
    self.welfareArr = [NSMutableArray array];
    self.takeoutArr = [NSMutableArray array];
    self.remarkArr = [NSMutableArray array];
    
    [self.infoArr addObject:@{@"发放月份":self.salaryModel.smonth}];
    [self.infoArr addObject:@{@"工号":self.salaryModel.icode}];
    [self.infoArr addObject:@{@"姓名":self.salaryModel.iname}];
    [self.infoArr addObject:@{@"发放部门":self.salaryModel.deptName}];
    [self.infoArr addObject:@{@"月基本工资":self.salaryModel.mbasePay}];
    [self.infoArr addObject:@{@"月绩效工资":self.salaryModel.mperfPay}];
    
    [self.payArr addObject:@{@"基本工资":self.salaryModel.basePay}];
    [self.payArr addObject:@{@"绩效工资":self.salaryModel.perfPay}];
    [self.payArr addObject:@{@"加班工资":self.salaryModel.otPay}];
    [self.payArr addObject:@{@"奖金":self.salaryModel.bonus}];
    [self.payArr addObject:@{@"合计":self.salaryModel.shTotal}];
    
    [self.welfareArr addObject:@{@"餐补":self.salaryModel.mealAllowance}];
    [self.welfareArr addObject:@{@"住房补贴":self.salaryModel.housingSubsidy}];
    [self.welfareArr addObject:@{@"通讯补贴":self.salaryModel.comtSubsidy}];
    [self.welfareArr addObject:@{@"交通补贴":self.salaryModel.trafficSubsidy}];
    [self.welfareArr addObject:@{@"高温补贴":self.salaryModel.highTemSubsidy}];
    [self.welfareArr addObject:@{@"其他补贴":self.salaryModel.otherSubsidy}];
    [self.welfareArr addObject:@{@"补发/补扣":self.salaryModel.reissueBuckle}];
    [self.welfareArr addObject:@{@"合计":self.salaryModel.subTotal}];
    
    [self.takeoutArr addObject:@{@"社保":self.salaryModel.socialSecurity}];
    [self.takeoutArr addObject:@{@"公积金":self.salaryModel.acctFund}];
    [self.takeoutArr addObject:@{@"个税":self.salaryModel.pit}];
    [self.takeoutArr addObject:@{@"其他":self.salaryModel.otherBuckle}];
    [self.takeoutArr addObject:@{@"合计":self.salaryModel.pitTotal}];
    [self.remarkArr addObject:@{@"remark":self.salaryModel.remark}];
    
    [self.dataSourceArray addObject:_infoArr];
    [self.dataSourceArray addObject:_payArr];
    [self.dataSourceArray addObject:_welfareArr];
    [self.dataSourceArray addObject:_takeoutArr];
    [self.dataSourceArray addObject:_remarkArr];
    
    [self.tableView reloadData];
    
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSourceArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return [(NSArray *)(self.dataSourceArray[section]) count];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == self.dataSourceArray.count - 1) {
         return [tableView fd_heightForCellWithIdentifier:@"YSSalaryRemarkCell" cacheByIndexPath:indexPath configuration:^(YSSalaryRemarkCell *cell) {

        cell.remarkLb.text = self.dataSourceArray[indexPath.section][indexPath.row][@"remark"];

        }];
    }else{
        return 40*kHeightScale;
    }
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == self.dataSourceArray.count - 1) {
        YSSalaryRemarkCell *cell = [[YSSalaryRemarkCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"YSSalaryRemarkCell"];
        cell.dic = self.dataSourceArray[indexPath.section][indexPath.row];
        return cell;
    }else{
        //    YSSalaryCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YSSalaryCell"];
        //    if (cell == nil) {
        YSSalaryCell *cell = [[YSSalaryCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"YSSalaryCell"];
        //    }
        cell.dic = self.dataSourceArray[indexPath.section][indexPath.row];
        [cell setOtherByIndexPath:indexPath withArray:self.dataSourceArray[indexPath.section]];//设置圆角 字体
        return cell;
    }
    
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = kUIColor(229, 229, 229, 1);
    UILabel *label = [[UILabel alloc]init];
    [view addSubview:label];
    [label sizeToFit];
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = kUIColor(102, 102, 102, 1);
    
    label.text = self.titleArray[section];
    label.frame = CGRectMake(15, (38 - 20)/2, kSCREEN_WIDTH, 20);
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 38;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
